package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.cty.ctyms.timejob.common.ConfigEnum;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSDAO;

/**
 * 短信统一发送控制类
 * 
 * @author chengshichao 创建时间：2012-12-11
 */
public class SMSInfoDAO {

	private static final int assignTime = 30;

	private IBaseDAO baseDAO;

	private ITransactionDAO tranDAO;

	private UserInfoDAO userInfoDAO;
	
	private List<String> smsSendList;
	
	/**
	 * @return the baseDAO
	 */
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	/**
	 * @param baseDAO
	 *            the baseDAO to set
	 */
	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	/**
	 * @return the tranDAO
	 */
	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}

	/**
	 * @param tranDAO
	 *            the tranDAO to set
	 */
	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}

	/**
	 * @return the userInfoDAO
	 */
	public UserInfoDAO getUserInfoDAO() {
		return userInfoDAO;
	}

	/**
	 * @param userInfoDAO
	 *            the userInfoDAO to set
	 */
	public void setUserInfoDAO(UserInfoDAO userInfoDAO) {
		this.userInfoDAO = userInfoDAO;
	}

	
	
	public List<String> getSmsSendList() {
		return smsSendList;
	}

	public void setSmsSendList(List<String> smsSendList) {
		this.smsSendList = smsSendList;
	}

	/**
	 * 获得发送时间
	 */
	public String getTimingSendTime(String SC_Type) {
		String sendTime = "";
		try {
			List<String> smsSendTimeList = this.getSMSCfgSendTime(SC_Type);
			String SC_SendTime_Bgn = smsSendTimeList.get(0);
			String SC_SendTime_End = smsSendTimeList.get(1);
			long nowTimel = DateUtil.now().getTime();
			long beginl = DateUtil.toDate(
					DateUtil.toString(DateUtil.now(), "yyyy-MM-dd") + " "
							+ SC_SendTime_Bgn, "yyyy-MM-dd HH:mm:ss").getTime();
			long endl = DateUtil.toDate(
					DateUtil.toString(DateUtil.now(), "yyyy-MM-dd") + " "
							+ SC_SendTime_End, "yyyy-MM-dd HH:mm:ss").getTime();
			// 发送规则
			if (beginl <= nowTimel && nowTimel <= endl) {
				sendTime = "null";
			} else if (beginl > nowTimel) {
				sendTime = "'"+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd")+" "+SC_SendTime_Bgn+"'";
			} else {
				Calendar calendar = Calendar.getInstance();
				calendar.add(Calendar.DAY_OF_YEAR, 1);
				sendTime = "'"+DateUtil.toString(calendar.getTime(), "yyyy-MM-dd")+" "+SC_SendTime_Bgn+"'";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sendTime;
	}
	
	/**
	 * 获得发送时间	故障
	 * @param SC_Type
	 * @return
	 */
	public String getTimingSendTimeFlt(List<String> smsSendTimeList) {
		String sendTime = "null";
		try {
			String SC_SendTime_Bgn = smsSendTimeList.get(0);
			String SC_SendTime_End = smsSendTimeList.get(1);
//			String nowTimeStr = DateUtil.toString(DateUtil.now());
			long nowTimel = DateUtil.now().getTime();
			long beginl = DateUtil.toDate(
					DateUtil.toString(DateUtil.now(), "yyyy-MM-dd") + " "
							+ SC_SendTime_Bgn, "yyyy-MM-dd HH:mm:ss").getTime();
			long endl = DateUtil.toDate(
					DateUtil.toString(DateUtil.now(), "yyyy-MM-dd") + " "
							+ SC_SendTime_End, "yyyy-MM-dd HH:mm:ss").getTime();
			// 发送规则
			if (beginl <= nowTimel && nowTimel <= endl) {
//				sendTime = nowTimeStr;
				sendTime = "null";
			} else if (beginl > nowTimel) {
//				sendTime = DateUtil.toString(DateUtil.now(), "yyyy-MM-dd")
//						+ " " + SC_SendTime_Bgn;
				sendTime = "'"+DateUtil.toString(DateUtil.now(), "yyyy-MM-dd")+" "+SC_SendTime_Bgn+"'";
			} else {
//				java.util.Calendar calendar = java.util.Calendar.getInstance();
//				calendar.roll(java.util.Calendar.DAY_OF_YEAR, 1);
				Calendar calendar = Calendar.getInstance();
				calendar.add(Calendar.DAY_OF_YEAR, 1);
//				sendTime = DateUtil.toString(calendar.getTime(), "yyyy-MM-dd")
//						+ " " + SC_SendTime_Bgn;
				sendTime = "'"+DateUtil.toString(calendar.getTime(), "yyyy-MM-dd")+" "+SC_SendTime_Bgn+"'";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sendTime;
	}
	
	/**
	 * 加载短信信息
	 * 
	 * @param sqlList
	 * @param paramList
	 * @param SMSMap
	 *            短信信息： SMSType：短信设置信息表-载重信息发送字段，该字段用来标识用户是否进行了载重信息发送设置
	 *            TabName：信息来源表名 SMSContent：发送信息内容
	 *            PromptType：提醒类型，（1：故障；2：报警；3：保养；4：司机行为；5：载重监控）
	 *            CreateType：生成方式，（1：自动；0：手动） DBName：信息来源库名
	 *            SMSCfgType：短信配置类型，用来获取短信发送时间 DBCode：设备所属机构Code
	 * 
	 */
	public void loadSMSInfo(List<String> sqlList, List<Object[]> paramList,
			Map<String, Object> SMSMap, List<Map<String, Object>> userList) {
		// 遍历短信发送人员，进行批处理发送
		for (Map<String, Object> userMap : userList) {
			String smsSendTime = this.getTimingSendTime(MapGetter.getString(
					SMSMap, "SMSCfgType"));
			if (StringUtil.isNullOrEmpty(smsSendTime)) {
				// 业务记录短信信息
				String strSqlSMSRec = "insert into SMS_SendRecord(SSR_MsgID,SSR_MsgCID,SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,"
						+ "SSR_CreateType,SSR_DBName,SSR_TableName)"
						+ "values(IDENT_CURRENT('"
						+ MapGetter.getString(SMSMap, "TabName")
						+ "'),IDENT_CURRENT('"
						+ MapGetter.getString(SMSMap, "TabName")
						+ "'),?,?,?,?," + (smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+ ",?,?,?,?);";


				sqlList.add(strSqlSMSRec);
				//sqlList.add(strSqlSMSSend);

				paramList.add(new Object[] {
						MapGetter.getString(userMap, "UserID"),
						MapGetter.getString(userMap, "UserName"),
						MapGetter.getString(userMap, "Mobile"),
						MapGetter.getString(SMSMap, "SMSContent"),
						MapGetter.getString(SMSMap, "PromptType"),
						MapGetter.getString(SMSMap, "CreateType"),
						MapGetter.getString(SMSMap, "DBName"),
						MapGetter.getString(SMSMap, "TabNameShort") });
				paramList.add(new Object[] {
						MapGetter.getString(userMap, "Mobile"),
						ConfigEnum.SourceNumber.getName(),
						MapGetter.getString(SMSMap, "SMSContent"), "-1"});
			}
		}
	}

	/**
	 * 
	 * @param sqlList
	 * @param paramList
	 * @param SMSMap
	 *            短信信息： MsgID：信息ID MsgCID：信息内容ID
	 *            SMSType：短信设置信息表-载重信息发送字段，该字段用来标识用户是否进行了载重信息发送设置 TabName：信息来源表名
	 *            SMSContent：发送信息内容
	 *            PromptType：提醒类型，（1：故障；2：报警；3：保养；4：司机行为；5：载重监控）
	 *            CreateType：生成方式，（1：自动；0：手动） DBName：信息来源库名
	 *            SMSCfgType：短信配置类型，用来获取短信发送时间 DBCode：设备所属机构Code 2013.04.08
	 *            haoyang 修改,将短信接收人 作为参数传入.
	 */
	public void promptSMSInfo(List<String> sqlList, List<Object[]> paramList,
			Map<String, Object> SMSMap, List<Map<String, Object>> userList) {
		// 获取短信发送人员
		// List<Map<String,Object>> userList =
		// userInfoDAO.getUserInfo(MapGetter.getString(SMSMap, "DBCode"),
		// MapGetter.getString(SMSMap, "SMSType"));

		String smsuser = "";
		// 遍历短信发送人员，进行批处理发送
		for (Map<String, Object> userMap : userList) {
			String smsSendTime = this.getTimingSendTime(MapGetter.getString(
					SMSMap, "SMSCfgType"));
			if (StringUtil.isNullOrEmpty(smsSendTime)) {
				smsuser += "，"+MapGetter.getString(userMap,"UserName");
				// 业务记录短信信息
				String strSqlSMSRec = "insert into SMS_SendRecord(SSR_MsgID,SSR_MsgCID,SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,"
						+ "SSR_CreateType,SSR_DBName,SSR_TableName)"
						+ "values(?,?,?,?,?,?,"+(smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+",?,?,?,?);";

				// 发送短信信息
			//	String strSqlSMSSend = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
				//		+ "values(?,?,?,?,"+smsSendTime+");";

				sqlList.add(strSqlSMSRec);
				//sqlList.add(strSqlSMSSend);

				paramList.add(new Object[] {
						MapGetter.getString(SMSMap, "MsgID"),
						MapGetter.getString(SMSMap, "MsgCID"),
						MapGetter.getString(userMap, "UserID"),
						MapGetter.getString(userMap, "UserName"),
						MapGetter.getString(userMap, "Mobile"),
						MapGetter.getString(SMSMap, "SMSContent"),
						MapGetter.getString(SMSMap, "PromptType"),
						MapGetter.getString(SMSMap, "CreateType"),
						MapGetter.getString(SMSMap, "DBName"),
						MapGetter.getString(SMSMap, "TabName") });
				paramList.add(new Object[] {
						MapGetter.getString(userMap, "Mobile"),
						ConfigEnum.SourceNumber.getName(),
						MapGetter.getString(SMSMap, "SMSContent"), "-1"});
			}
		}
		
		if(StringUtil.isValid(smsuser)){
			smsuser += "，";
		}
		SMSMap.put("smsuser", smsuser);
	}
	
	/**
	 * 发送短信	故障
	 * @param sqlList
	 * @param paramList
	 * @param SMSMap
	 * @param userList
	 */
	public boolean promptSMSInfoFlt(List<String> sqlList, List<Object[]> paramList,
			Map<String, Object> SMSMap, Map<String, Object> user, List<String> smsSendTimeList ,String smsSendType) {
		//类型（1：短信白名单；2：短信过滤；3：实时发送短信）
		String SMSFC_Type = MapGetter.getString(user, "SMSFC_Type");
		//实时发送短信故障码—红色故障（1：选中）
		String SMSAS_SMSFltIsRed = MapGetter.getString(user, "SMSAS_SMSFltIsRed");
		//故障代码颜色
		String SysISM_CodeColorInfo = MapGetter.getString(SMSMap, "SysISM_CodeColorInfo");
		//短信--红色故障
		String SMSAS_SMSFltRed = MapGetter.getString(user, "SMSAS_SMSFltRed");
		//短信--黄色故障
		String SMSAS_SMSFltYellow = MapGetter.getString(user, "SMSAS_SMSFltYellow");
		//短信--其他故障
		String SMSAS_SMSFltOther = MapGetter.getString(user, "SMSAS_SMSFltOther");
		//故障分类
		String SMSAS_FltType = MapGetter.getString(user, "SMSAS_FltType");
		//短信--实时发送短信故障码—四级故障（1：选中）
		String SMSAS_SMSFltIsFour = MapGetter.getString(user, "SMSAS_SMSFltIsFour");
		//故障等级
		String fltLv = MapGetter.getString(SMSMap, "fltLv");
		//一级故障
		String SMSAS_SMSFltOne = MapGetter.getString(user, "SMSAS_SMSFltOne");
		//二级故障
		String SMSAS_SMSFltTwo = MapGetter.getString(user, "SMSAS_SMSFltTwo");
		//三级故障
		String SMSAS_SMSFltThree = MapGetter.getString(user, "SMSAS_SMSFltThree");
		//四级故障
		String SMSAS_SMSFltFour = MapGetter.getString(user, "SMSAS_SMSFltFour");
		
		String smsSendTime = "";
		if(SMSFC_Type.equals("3") || ((SMSAS_FltType.equals("2") && SMSAS_SMSFltIsRed.equals("true") && SysISM_CodeColorInfo.equals(ConfigEnum.FltCodeRed.getName())) || (SMSAS_FltType.equals("1") && SMSAS_SMSFltIsFour.equals("true") && fltLv.equals("4")))){	//实时发送
//			smsSendTime = "GETDATE()";
			smsSendTime = "null";
		}else if(SMSFC_Type.equals("1") || ( SMSAS_FltType.equals("2") && (SMSAS_SMSFltRed.equals(SysISM_CodeColorInfo) || SMSAS_SMSFltYellow.equals(SysISM_CodeColorInfo) 
				|| (SMSAS_SMSFltOther.equals("其他") && !SysISM_CodeColorInfo.equals("黄色")&& !SysISM_CodeColorInfo.equals("红色"))))
				|| ( SMSAS_FltType.equals("1") && ((SMSAS_SMSFltOne.equals("true")&&fltLv.equals("1")) || (SMSAS_SMSFltTwo.equals("true")&&fltLv.equals("2")) || (SMSAS_SMSFltThree.equals("true")&&fltLv.equals("3")) || (SMSAS_SMSFltFour.equals("true")&&fltLv.equals("4"))))){
			smsSendTime = this.getTimingSendTimeFlt(smsSendTimeList);
		}
		
		if (StringUtil.isNullOrEmpty(smsSendTime)) {
			// 业务记录短信信息
			String strSqlSMSRec = "insert into SMS_SendRecord(SSR_MsgID,SSR_MsgCID,SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,"
					+ "SSR_CreateType,SSR_DBName,SSR_TableName)"
					+ "values(?,?,?,?,?,?,"+(smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+",?,?,?,?);";

			// 发送短信信息
			//String strSqlSMSSend = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
				//	+ "values(?,?,?,?,"+smsSendTime+");";

			sqlList.add(strSqlSMSRec);
			//sqlList.add(strSqlSMSSend);

			paramList.add(new Object[] {
					MapGetter.getString(SMSMap, "MsgID"),
					MapGetter.getString(SMSMap, "MsgCID"),
					MapGetter.getString(user, "UserID"),
					MapGetter.getString(user, "UserName"),
					MapGetter.getString(user, "Mobile"),
					MapGetter.getString(SMSMap, "SMSContent"),
					//MapGetter.getString(SMSMap, "PromptType"),
					"".equals(smsSendType)?MapGetter.getString(SMSMap, "PromptType"):smsSendType,
					MapGetter.getString(SMSMap, "CreateType"),
					MapGetter.getString(SMSMap, "DBName"),
					MapGetter.getString(SMSMap, "TabName") });
			paramList.add(new Object[] {
					MapGetter.getString(user, "Mobile"),
					ConfigEnum.SourceNumber.getName(),
					MapGetter.getString(SMSMap, "SMSContent"), "-1"});
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 指定时间内是否重复 SMSCfgType：短信配置类型，用来获取短信发送时间 isOccuredSQL：自定义判断是否重复发送SQL
	 * 说明：本方法通过数量进行判断，自定义SQL的目前结果集，必须是用COUNT，且别名为cnt
	 * 
	 * @return boolean false：无重复，可发送；true：有重复，不可发送
	 */
	public boolean assTimeIsOccured(String SMSCfgType, String isOccuredSQL) {
		// 获取配置的发送时间
		List<String> smsSendTimeList = this.getSMSCfgSendTime(SMSCfgType);
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		String SC_SendTime_Bgn = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(0);
		String SC_SendTime_End = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(1);
		StringBuffer strBuff = new StringBuffer();
		strBuff.append(isOccuredSQL);
		strBuff.append("and (SSR_CreateTime between DATEADD(mi,-" + assignTime
				+ ",GETDATE()) and GETDATE()) and ");
		strBuff.append("(convert(datetime,'" + nowTimeStr
				+ "',120) between convert(datetime,'" + SC_SendTime_Bgn
				+ "',120) and convert(datetime,'" + SC_SendTime_End + "',120))");
		Map<String, Object> retMap = baseDAO.execQueryOne(strBuff.toString(),
				new Object[] {});
		boolean flag = true;
		if (MapGetter.getString(retMap, "cnt").equals("0")) {
			flag = false;
		} else {
			flag = true;
		}
		return flag;
	}
	
	/**
	 * 判断在工作时间内，同一台车同一个故障在半个小时内是否发生过	故障
	 * @param SMSCfgType
	 * @param isOccuredSQL
	 * @param Type	类型（1：统一设置；2：单独设置）
	 * @param TimeBgn	单独设置的开始时间
	 * @param TimeEnd	单独设置的结束时间
	 * @return
	 */
	public boolean assTimeIsOccuredFlt(List<String> smsSendTimeList, String isOccuredSQL) {
		// 获取配置的发送时间
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		String SC_SendTime_Bgn = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(0);
		String SC_SendTime_End = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(1);
		StringBuffer strBuff = new StringBuffer();
		strBuff.append(isOccuredSQL);
		strBuff.append("and (SSR_CreateTime between DATEADD(mi,-" + assignTime
				+ ",GETDATE()) and GETDATE()) and ");
		strBuff.append("(convert(datetime,'" + nowTimeStr
				+ "',120) between convert(datetime,'" + SC_SendTime_Bgn
				+ "',120) and convert(datetime,'" + SC_SendTime_End + "',120))");
		Map<String, Object> retMap = baseDAO.execQueryOne(strBuff.toString(),
				new Object[] {});
		boolean flag = true;
		if (MapGetter.getString(retMap, "cnt").equals("0")) {
			flag = false;
		} else {
			flag = true;
		}
		return flag;
	}

	/**
	 * 非工作时间内是否重复，即第二天工作时间起点只发一次
	 * 
	 * @param SMSCfgType
	 *            短信配置类型，用来获取短信发送时间
	 * @param tipTimeColumnName
	 *            提示时间字段名称
	 * @param nowTipTime
	 *            当前提示时间
	 * @param isOccuredSQL
	 *            自定义判断是否重复发送SQL 说明：本方法通过数量进行判断，自定义SQL的目前结果集，必须是用COUNT，且别名为cnt
	 * @return boolean false：无重复，可发送；true：有重复，不可发送
	 */
	public boolean nonWorkIsOccured(String SMSCfgType,
			String tipTimeColumnName, String nowTipTime, String isOccuredSQL) {
		String sql = "select * from SMS_Config where SC_Type=?";
		Map<String, Object> hm = this.baseDAO.execQueryOne(sql,
				new Object[] { SMSCfgType });
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		String SC_SendTime_Bgn = hm.get("SC_SendTime_Bgn") != null ? nowTimeStr
				.substring(0, 10)
				+ " "
				+ hm.get("SC_SendTime_Bgn").toString()
				+ ":00" : ConfigEnum.SendTime_Bgn.getName();
		String SC_SendTime_End = hm.get("SC_SendTime_End") != null ? nowTimeStr
				.substring(0, 10)
				+ " "
				+ hm.get("SC_SendTime_End").toString()
				+ ":00" : ConfigEnum.SendTime_End.getName();

		String SC_SendTime_Bgn_Next = hm.get("SC_SendTime_Bgn") != null ? DateUtil
				.addDay(1) + " " + hm.get("SC_SendTime_Bgn").toString() + ":00"
				: ConfigEnum.SendTime_Bgn.getName();
		String SC_SendTime_End_Up = hm.get("SC_SendTime_End") != null ? DateUtil
				.addDay(-1)
				+ " "
				+ hm.get("SC_SendTime_End").toString()
				+ ":00" : ConfigEnum.SendTime_End.getName();

		// 条件
		String where = " and (" + tipTimeColumnName
				+ " between convert(datetime,'" + SC_SendTime_End + "',120) "
				+ "and convert(datetime,'" + SC_SendTime_Bgn_Next
				+ "',120) and convert(datetime,'" + nowTipTime
				+ "',120)>convert(datetime,'" + SC_SendTime_End + "',120)) or "
				+ "(" + tipTimeColumnName + " between convert(datetime,'"
				+ SC_SendTime_End_Up + "',120) and convert(datetime,'"
				+ SC_SendTime_Bgn + "',120) " + "and convert(datetime,'"
				+ nowTipTime + "',120)<convert(datetime,'" + SC_SendTime_Bgn
				+ "',120))";
		String retSQL = isOccuredSQL + where;
		Map<String, Object> retMap = baseDAO.execQueryOne(retSQL,
				new Object[] {});
		boolean flag = true;
		if (MapGetter.getString(retMap, "cnt").equals("0")) {
			flag = false;
		} else {
			flag = true;
		}
		return flag;
	}
	
	/**
	 * 非工作时间内是否重复，即第二天工作时间起点只发一次	故障
	 * @param SMSCfgType
	 * @param tipTimeColumnName
	 * @param nowTipTime
	 * @param isOccuredSQL
	 * @return
	 */
	public boolean nonWorkIsOccuredFlt(List<String> smsSendTimeList,
			String tipTimeColumnName, String nowTipTime, String isOccuredSQL) {
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		String SC_SendTime_Bgn = nowTimeStr.substring(0, 10)+ " "+ smsSendTimeList.get(0)+ ":00";
		String SC_SendTime_End = nowTimeStr.substring(0, 10)+ " "+ smsSendTimeList.get(1)+ ":00";

		String SC_SendTime_Bgn_Next = DateUtil.addDay(1) + " " + smsSendTimeList.get(0)+ ":00";
		String SC_SendTime_End_Up = DateUtil.addDay(-1)+ " " + smsSendTimeList.get(1)+ ":00";

		// 条件
		String where = " and (" + tipTimeColumnName
				+ " between convert(datetime,'" + SC_SendTime_End + "',120) "
				+ "and convert(datetime,'" + SC_SendTime_Bgn_Next
				+ "',120) and convert(datetime,'" + nowTipTime
				+ "',120)>convert(datetime,'" + SC_SendTime_End + "',120)) or "
				+ "(" + tipTimeColumnName + " between convert(datetime,'"
				+ SC_SendTime_End_Up + "',120) and convert(datetime,'"
				+ SC_SendTime_Bgn + "',120) " + "and convert(datetime,'"
				+ nowTipTime + "',120)<convert(datetime,'" + SC_SendTime_Bgn
				+ "',120))";
		String retSQL = isOccuredSQL + where;
		Map<String, Object> retMap = baseDAO.execQueryOne(retSQL,
				new Object[] {});
		boolean flag = true;
		if (MapGetter.getString(retMap, "cnt").equals("0")) {
			flag = false;
		} else {
			flag = true;
		}
		return flag;
	}

	/**
	 * 获取短信配置发送时间
	 * 
	 * @param SC_Type
	 * @return
	 */
	public List<String> getSMSCfgSendTime(String SC_Type) {

		String sql = "select * from SMS_Config where SC_Type=?";
		Map<String, Object> hm = this.baseDAO.execQueryOne(sql,
				new Object[] { SC_Type });
		String SC_SendTime_Bgn = hm.get("SC_SendTime_Bgn") != null ? hm.get(
				"SC_SendTime_Bgn").toString()
				+ ":00" : ConfigEnum.SendTime_Bgn.getName();
		String SC_SendTime_End = hm.get("SC_SendTime_End") != null ? hm.get(
				"SC_SendTime_End").toString()
				+ ":00" : ConfigEnum.SendTime_End.getName();

		List<String> list = new ArrayList<String>();
		list.add(SC_SendTime_Bgn);
		list.add(SC_SendTime_End);
		return list;
	}

	/**
	 * 获取 (发送间隔-扫描间隔:30-5=25min之前的短信发送记录) 工作时间内 目前只支持:故障报警(1),故障解除(7),报警(2)
	 */
	public List<String> getSmsMsgBeforeSomeTime(String SMSCfgType) {
		List<String> sms = new ArrayList<String>();
		// 获取配置的发送时间
		List<String> smsSendTimeList = this.getSMSCfgSendTime(SMSCfgType);
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		String SC_SendTime_Bgn = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(0);
		String SC_SendTime_End = nowTimeStr.substring(0, 10) + " "
				+ smsSendTimeList.get(1);
		String sql = "";
		if ("1".equals(SMSCfgType) || "7".equals(SMSCfgType)) {
			sql = "SELECT Cast(vcl_id AS VARCHAR) + '_' + Cast(fltcode AS VARCHAR) AS uniqueID"
					+ " FROM   (SELECT msgf_vcl_id AS vcl_id,"
					+ "                sysism_code AS fltcode"
					+ "         FROM   sms_sendrecord AS ssr"
					+ "                INNER JOIN cty_egn_a.dbo.msg_flt_content AS mfc"
					+ "                  ON mfc.msgfco_id = ssr.ssr_msgcid"
					+ "                INNER JOIN cty_egn_a.dbo.msg_flt AS mf"
					+ "                  ON mf.msgf_id = mfc.msgfco_msgf_id"
					+ "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"
					+ "                  ON fi.sysism_fmi = mfc.msgfco_faultfmi"
					+ "                     AND fi.sysism_spn = mfc.msgfco_faultspn"
					+ "         WHERE  1 = 1"
					+ "                AND ssr_type = "
					+ SMSCfgType
					+ "                AND (ssr_createtime BETWEEN Dateadd(mi,-25,Getdate())"
					+ "                                            AND Getdate())"
					+ "                AND (Convert(datetime,'"
					+ nowTimeStr
					+ "',120) BETWEEN Convert(datetime,'"
					+ SC_SendTime_Bgn
					+ "',120)"
					+ "                                                      AND Convert(datetime,'"
					+ SC_SendTime_End
					+ "',120))"
					+ "         UNION "
					+ "         SELECT msgf_vcl_id,"
					+ "                sysism_code"
					+ "         FROM   sms_sendrecord AS ssr"
					+ "                INNER JOIN cty_egn_b.dbo.msg_flt_content AS mfc"
					+ "                  ON mfc.msgfco_id = ssr.ssr_msgcid"
					+ "                INNER JOIN cty_egn_b.dbo.msg_flt AS mf"
					+ "                  ON mf.msgf_id = mfc.msgfco_msgf_id"
					+ "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"
					+ "                  ON fi.sysism_fmi = mfc.msgfco_faultfmi"
					+ "                     AND fi.sysism_spn = mfc.msgfco_faultspn"
					+ "         WHERE  1 = 1"
					+ "                AND ssr_type = "
					+ SMSCfgType
					+ "                AND (ssr_createtime BETWEEN Dateadd(mi,-25,Getdate())"
					+ "                                            AND Getdate())"
					+ "                AND (Convert(datetime,'"
					+ nowTimeStr
					+ "',120) BETWEEN Convert(datetime,'"
					+ SC_SendTime_Bgn
					+ "',120)"
					+ "                                                      AND Convert(datetime,'"
					+ SC_SendTime_End
					+ "',120))"
					+ "         UNION "
					+ "         SELECT msgfu_vcl_id,"
					+ "                sysism_code"
					+ "         FROM   sms_sendrecord AS ssr"
					+ "                INNER JOIN cty_egn_b.dbo.msg_flt_uds_content AS mfc"
					+ "                  ON mfc.msgfuc_id = ssr.ssr_msgcid"
					+ "                INNER JOIN cty_egn_b.dbo.msg_flt_uds AS mf"
					+ "                  ON mf.msgfu_id = mfc.msgfuc_msgfu_id"
					+ "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"
					+ "                  ON fi.sysism_fmi = mfc.msgfuc_fltfmi"
					+ "                     AND fi.sysism_spn = mfc.msgfuc_fltspn"
					+ "         WHERE  1 = 1"
					+ "                AND ssr_type = "
					+ SMSCfgType
					+ "                AND (ssr_createtime BETWEEN Dateadd(mi,-25,Getdate())"
					+ "                                            AND Getdate())"
					+ "                AND (Convert(datetime,'"
					+ nowTimeStr
					+ "',120) BETWEEN Convert(datetime,'"
					+ SC_SendTime_Bgn
					+ "',120)"
					+ "                                                      AND Convert(datetime,'"
					+ SC_SendTime_End + "',120))) TEMP";
		} else if ("2".equals(SMSCfgType)) {
			sql = "SELECT Cast(vclid AS VARCHAR) + '_' + Cast(alarmid AS VARCHAR) AS uniqueID"
					+ " FROM   (SELECT msgalm_vcl_id vclid,"
					+ "                alm_id alarmid"
					+ "         FROM   sms_sendrecord AS sra"
					+ "                INNER JOIN cty_egn_a.dbo.msg_alarm_content AS mac"
					+ "                  ON sra.ssr_msgcid = mac.msgalmc_id"
					+ "                INNER JOIN cty_egn_a.dbo.msg_alarm AS ma"
					+ "                  ON mac.msgalmc_msgalm_id = ma.msgalm_id"
					+ "                INNER JOIN cty_egn_a.dbo.alarm_item AS sa"
					+ "                  ON sa.alm_id = mac.msgalmc_alm_id"
					+ "         WHERE  1 = 1"
					+ "                AND ssr_type = 2"
					+ "                AND (ssr_createtime BETWEEN Dateadd(mi,-25,Getdate())"
					+ "                                            AND Getdate())"
					+ "                AND (Convert(datetime,'"
					+ nowTimeStr
					+ "',120) BETWEEN Convert(datetime,'"
					+ SC_SendTime_Bgn
					+ "',120)"
					+ "                                                      AND Convert(datetime,'"
					+ SC_SendTime_End
					+ "',120))"
					+ "         UNION "
					+ "         SELECT msgalm_vcl_id,"
					+ "                sysa_id"
					+ "         FROM   sms_sendrecord AS sra"
					+ "                INNER JOIN cty_egn_b.dbo.msg_alarm_content AS mac"
					+ "                  ON sra.ssr_msgcid = mac.msgalmc_id"
					+ "                INNER JOIN cty_egn_b.dbo.msg_alarm AS ma"
					+ "                  ON mac.msgalmc_msgalm_id = ma.msgalm_id"
					+ "                INNER JOIN cty_egn_b.dbo.sys_alarm AS sa"
					+ "                  ON sa.sysa_id = mac.msgalmc_sysa_id"
					+ "         WHERE  1 = 1"
					+ "                AND ssr_type = 2"
					+ "                AND (ssr_createtime BETWEEN Dateadd(mi,-25,Getdate())"
					+ "                                            AND Getdate())"
					+ "                AND (Convert(datetime,'"
					+ nowTimeStr
					+ "',120) BETWEEN Convert(datetime,'"
					+ SC_SendTime_Bgn
					+ "',120)"
					+ "                                                      AND Convert(datetime,'"
					+ SC_SendTime_End + "',120))) TEMP";
		}
		if(StringUtil.isNullOrEmpty(sql)){
			List<Map<String,Object>> list = baseDAO.execQuery(sql, new Object[]{});
			for (Map<String, Object> map : list) {
				sms.add(MapGetter.getString(map, "uniqueID"));
			}
		}
		return sms;
	}

	/**
	 * 获取第二天 工作时间发送的短信
	 * 只支持:故障报警(1),故障解除(7),报警(2)
	 */
	public List<String> getSmsMsgSecondDay(String SMSCfgType){
		List<String> sms = new ArrayList<String>();
		String sql = "select * from SMS_Config where SC_Type=?";
		Map<String, Object> hm = this.baseDAO.execQueryOne(sql,
				new Object[] { SMSCfgType });
		//当前时间
		String nowTimeStr = DateUtil.toString(DateUtil.now());
		//短信发送开始 时间
		String SC_SendTime_Bgn = hm.get("SC_SendTime_Bgn") != null ? nowTimeStr
				.substring(0, 10)
				+ " "
				+ hm.get("SC_SendTime_Bgn").toString()
				+ ":00" : ConfigEnum.SendTime_Bgn.getName();
		//短信发送结束时间
		String SC_SendTime_End = hm.get("SC_SendTime_End") != null ? nowTimeStr
				.substring(0, 10)
				+ " "
				+ hm.get("SC_SendTime_End").toString()
				+ ":00" : ConfigEnum.SendTime_End.getName();
		//短信发送第二天开始时间
		String SC_SendTime_Bgn_Next = hm.get("SC_SendTime_Bgn") != null ? DateUtil
				.addDay(1) + " " + hm.get("SC_SendTime_Bgn").toString() + ":00"
				: ConfigEnum.SendTime_Bgn.getName();
		
		sql = "";
		if("1".equals(SMSCfgType)||"7".equals(SMSCfgType)){
			sql = "SELECT Cast(vcl_id AS VARCHAR) + '_' + Cast(fltcode AS VARCHAR) AS uniqueID"+
					 " FROM   (SELECT msgf_vcl_id AS vcl_id,"+
					 "                sysism_code AS fltcode"+
					 "         FROM   sms_sendrecord AS ssr"+
					 "                INNER JOIN cty_egn_a.dbo.msg_flt_content AS mfc"+
					 "                  ON mfc.msgfco_id = ssr.ssr_msgcid"+
					 "                INNER JOIN cty_egn_a.dbo.msg_flt AS mf"+
					 "                  ON mf.msgf_id = mfc.msgfco_msgf_id"+
					 "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"+
					 "                  ON fi.sysism_fmi = mfc.msgfco_faultfmi"+
					 "                     AND fi.sysism_spn = mfc.msgfco_faultspn"+
					 "         WHERE  1 = 1"+
					 "                AND ssr_type = "+SMSCfgType+
					 "                AND ('"+nowTimeStr+"' > Convert(datetime,'"+SC_SendTime_End+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn_Next+"',120))"+
					 "                 OR ('"+nowTimeStr+"' < Convert(datetime,'"+SC_SendTime_Bgn+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn+"',120))"+
					 "         UNION "+
					 "         SELECT msgf_vcl_id,"+
					 "                sysism_code"+
					 "         FROM   sms_sendrecord AS ssr"+
					 "                INNER JOIN cty_egn_b.dbo.msg_flt_content AS mfc"+
					 "                  ON mfc.msgfco_id = ssr.ssr_msgcid"+
					 "                INNER JOIN cty_egn_b.dbo.msg_flt AS mf"+
					 "                  ON mf.msgf_id = mfc.msgfco_msgf_id"+
					 "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"+
					 "                  ON fi.sysism_fmi = mfc.msgfco_faultfmi"+
					 "                     AND fi.sysism_spn = mfc.msgfco_faultspn"+
					 "         WHERE  1 = 1"+
					 "                AND ssr_type = "+SMSCfgType+
					 "                AND ('"+nowTimeStr+"' > Convert(datetime,'"+SC_SendTime_End+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn_Next+"',120))"+
					 "                 OR ('"+nowTimeStr+"' < Convert(datetime,'"+SC_SendTime_Bgn+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn+"',120))"+
					 "         UNION "+
					 "         SELECT msgfu_vcl_id,"+
					 "                sysism_code"+
					 "         FROM   sms_sendrecord AS ssr"+
					 "                INNER JOIN cty_egn_b.dbo.msg_flt_uds_content AS mfc"+
					 "                  ON mfc.msgfuc_id = ssr.ssr_msgcid"+
					 "                INNER JOIN cty_egn_b.dbo.msg_flt_uds AS mf"+
					 "                  ON mf.msgfu_id = mfc.msgfuc_msgfu_id"+
					 "                INNER JOIN cty_vcl.dbo.sys_fltism AS fi"+
					 "                  ON fi.sysism_fmi = mfc.msgfuc_fltfmi"+
					 "                     AND fi.sysism_spn = mfc.msgfuc_fltspn"+
					 "         WHERE  1 = 1"+
					 "                AND ssr_type = "+SMSCfgType+
					 "                AND ('"+nowTimeStr+"' > Convert(datetime,'"+SC_SendTime_End+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn_Next+"',120))"+
					 "                 OR ('"+nowTimeStr+"' < Convert(datetime,'"+SC_SendTime_Bgn+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn+"',120))"+
					 ") TEMP";
		}else if("2".equals(SMSCfgType)){
			sql = "SELECT Cast(vclid AS VARCHAR) + '_' + Cast(almid AS VARCHAR) uniqueid"+
					 " FROM   (SELECT ma.msgalm_vcl_id vclid,"+
					 "                sa.alm_id almid"+
					 "         FROM   sms_sendrecord AS sra"+
					 "                INNER JOIN cty_egn_a.dbo.msg_alarm_content AS mac"+
					 "                  ON sra.ssr_msgcid = mac.msgalmc_id"+
					 "                INNER JOIN cty_egn_a.dbo.msg_alarm AS ma"+
					 "                  ON mac.msgalmc_msgalm_id = ma.msgalm_id"+
					 "                INNER JOIN cty_egn_a.dbo.alarm_item AS sa"+
					 "                  ON sa.alm_id = mac.msgalmc_alm_id"+
					 "         WHERE  1 = 1"+
					 "                AND ssr_type = 2"+
					 "                AND ('"+nowTimeStr+"' > Convert(datetime,'"+SC_SendTime_End+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn_Next+"',120))"+
					 "                 OR ('"+nowTimeStr+"' < Convert(datetime,'"+SC_SendTime_Bgn+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn+"',120))"+					 
					 "         UNION "+
					 "         SELECT ma.msgalm_vcl_id,"+
					 "                sa.sysa_id"+
					 "         FROM   sms_sendrecord AS sra"+
					 "                INNER JOIN cty_egn_b.dbo.msg_alarm_content AS mac"+
					 "                  ON sra.ssr_msgcid = mac.msgalmc_id"+
					 "                INNER JOIN cty_egn_b.dbo.msg_alarm AS ma"+
					 "                  ON mac.msgalmc_msgalm_id = ma.msgalm_id"+
					 "                INNER JOIN cty_egn_b.dbo.sys_alarm AS sa"+
					 "                  ON sa.sysa_id = mac.msgalmc_sysa_id"+
					 "         WHERE  1 = 1"+
					 "                AND ssr_type = 2"+
					 "                AND ('"+nowTimeStr+"' > Convert(datetime,'"+SC_SendTime_End+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn_Next+"',120))"+
					 "                 OR ('"+nowTimeStr+"' < Convert(datetime,'"+SC_SendTime_Bgn+"',120)"+
					 "                     AND ssr_createtime >= Convert(datetime,'"+SC_SendTime_Bgn+"',120))"+					 
					 ") TEMP";
		}
		List<Map<String,Object>> relist = baseDAO.execQuery(sql,
				new Object[] {});
		for (Map<String, Object> map : relist) {
			sms.add(MapGetter.getString(map, "uniqueID"));
		}
		
		return sms;
	}
	
	/**
	 * 获取 短信接收人 同时控制 短信发送 功能
	 * 
	 * @param DBCode
	 * @param SMSType
	 *            短信提示类型
	 * @return
	 * 2015.05.16 haoyang 将发送过滤 放入配置文件：applicationContext-generall.xml
	 */
	public List<Map<String, Object>> getSMSUsers(String SMSType,String DBCode,String VehicleID) {
		List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
		if (smsSendList.contains(SMSType))
			return userInfoDAO.getUserInfo(SMSType,DBCode, VehicleID);
		return userList;
	}
	
	/**
	 * 和上面的方法返回回值一致，
	 * 保养提示新 调用
	 */
	public List<Map<String, Object>> getSMSUsersOfMtnNew(String SMSType,String DBCode,String VehicleID) {
		if (smsSendList.contains("SMSAS_SMSMtnNew"))
			return userInfoDAO.getUserInfo(SMSType,DBCode, VehicleID);
		return null;
	}

	/**
	 * 获取 短信接收人
	 */
		// 拼接短信接收人
	public String getSMSUsers(List<Map<String, Object>> userList) {
		String recUser = "";
		for (Map<String, Object> map : userList) {
			if (StringUtil.isNullOrEmpty(MapGetter.getString(map, "UserName")))
				recUser += MapGetter.getString(map, "UserName") + "，";
		}
		return recUser;
	}
	
	/**
	 * 拼接短信接受人员ID
	 * @param userList
	 * @return
	 */
	public String getSMSUsersID(List<Map<String, Object>> userList) {
		// 拼接短信接收人
		String recUser = "";
		for (int i = 0; i < userList.size(); i++) {
			Map<String, Object> map = userList.get(i);
			if(i!=0 && StringUtil.isValid(recUser)){
				recUser += ",";
			}
			if (StringUtil.isNullOrEmpty(MapGetter.getString(map, "UserID"))){
				recUser += MapGetter.getString(map, "UserID");
			}
		}
		return recUser;
	}
	
	/**
	 * 获取故障提示短信接收人
	 * @param FltCode
	 * @param DBCode
	 * @param VehicleID
	 * @param SMSType	短信提示类型
	 * @return
	 */
	public List<Map<String,Object>> getSMSUsers_Flt(String FltCode,String DBCode,String VehicleID,String SMSType,boolean isRep){
		if (smsSendList.contains(SMSType)){
			String sql = "select distinct SMSAS_ID,ui.UserID,ui.UserName,ui.Mobile,ui.Email,ui.organizationcode as UserDBCode,ui.organizationname as UserDBName,smsas.SMSAS_SMSAtt, "
				+"smsfc.SMSFC_Type,SMSAS_SMSFltIsRed,SMSAS_SMSFltSendType,case SMSAS_SMSFltRed when 1 then '红色' else NULL end SMSAS_SMSFltRed, "
				+"case SMSAS_SMSFltYellow when 1 then '黄色' else NULL end SMSAS_SMSFltYellow, "
				+"case SMSAS_SMSFltOther when 1 then '其他' else NULL end SMSAS_SMSFltOther,SMSAS_SMSRels, "
				+"SMSAS_SMSFltSendBegin,SMSAS_SMSFltSendEnd "
				+",SMSAS_Type,SMSAS_IsServer,SMSAS_FltType,SMSAS_SMSFltFour,SMSAS_SMSFltThree,SMSAS_SMSFltTwo,SMSAS_SMSFltOne,SMSAS_SMSFltIsFour "
				//jiyongtian 增加查询故障12小时报警
				+",SMSAS_SMAFlttw "
				+"from SMS_Alarm_SetInfo as smsas "    
				+"inner Join v_userInfo_Organization_all as ui ON smsas.SMSAS_UsP_ID=ui.UserID "    
				+"left join SMSDB on smsas.SMSAS_ID=SMSDB_SMSAS_ID "
				+"left join SMSVcl on smsas.SMSAS_ID=SMSVcl_SMSAS_ID "
				+"left join (select SMSFC_SMSAS_ID,MAX(SMSFC_Type) as SMSFC_Type " 
				+"from SMSFltCode where SMSFC_FltCode=? group by SMSFC_SMSAS_ID) smsfc on smsfc.SMSFC_SMSAS_ID=smsas.SMSAS_ID "
				+"where ((smsas.SMSAS_SMSAtt=1  and SMSDB_DBCode=?) or (smsas.SMSAS_SMSAtt=2 and SMSVcl_VehicleID=? )) "
				+"and (SMSFC_Type is not null or SMSAS_SMSFltIsRed=1 or SMSAS_SMSFltRed=1 or SMSAS_SMSFltYellow=1 or SMSAS_SMSFltOther=1 or SMSAS_SMSFltFour = 1 or SMSAS_SMSFltThree = 1 or SMSAS_SMSFltTwo = 1 or SMSAS_SMSFltOne = 1 or SMSAS_SMSFltIsFour = 1) ";
			if(isRep){
				sql += " and SMSAS_SMAFlttw = 1 ";
			}
			return baseDAO.execQuery(sql, new Object[]{FltCode,DBCode,VehicleID});
		}else{
			return new ArrayList<Map<String,Object>>();
		}
		
	}
	/**
	 * 发送保养提示短信,(未处理短信内容超过60个字的情况)
	 * @param  List<Map<String,Object>> userList 短信接收人
	 * @param  Map<String, Object> vclInfo 保养车的具体信息
	 * @param  String armValue 保养内容
	 * @param  int mtnType 保养方式
	 * @author jiyongtian 20140530 IEMS3.6新增
	 * 
	 **/
	public String sendMailsOfmaintAlerts(List<Map<String,Object>> userList,Map<String, Object> vclInfo,
			String armValue, int mtnType,String isbakTable) {
		MyConnectDSDAO myConnectDSDAO=new MyConnectDSDAO();
		//提示中心，短信接收人中是中文逗号
		StringBuffer userName = new StringBuffer("，");
		if(null!= userList&&!userList.isEmpty()){
			//发送时间
			String sendTime = this.getTimingSendTime("2");
			for (Map<String, Object> userMap : userList) {
				StringBuffer sql = new StringBuffer();
				if(sendTime.toLowerCase().equals("null")){
					sql.append("insert into Note_MaintAlerts (NMA_VclID,NMA_SType,NMA_State,NMA_MsgContent,NMA_Position,NMA_UserID,NMA_UserName,NMA_UserDBCode,NMA_UserDBName,NMA_Mobile,NMA_SendTime)values(?,1,1,?,null,?,?,?,?,?,GETDATE());");
				} else{
					sql.append("insert into Note_MaintAlerts (NMA_VclID,NMA_SType,NMA_State,NMA_MsgContent,NMA_Position,NMA_UserID,NMA_UserName,NMA_UserDBCode,NMA_UserDBName,NMA_Mobile,NMA_SendTime)values(?,1,1,?,null,?,?,?,?,?,"+sendTime+");");
				}
				sql.append("insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)values(?,?,?,?,"+sendTime+");");
				String vclNo = MapGetter.getString(vclInfo,"VehicleNumber");
				userName.append(MapGetter.getString(userMap,"UserName")+"，");
				String Content = this.getContensOfMaintAlertMails(vclNo,armValue,mtnType);
				myConnectDSDAO.execUpdate(
						sql.toString(),
						new Object[] {vclInfo.get("VehicleID"),
							Content,
							userMap.get("UserID"),
							userMap.get("UserName"), 
							MapGetter.getString(userMap,"UserDBCode").substring(0,MapGetter.getString(userMap,"UserDBCode").length()-1),
							MapGetter.getString(userMap,"UserDBName").subSequence(0, MapGetter.getString(userMap,"UserDBName").length()-1),
							userMap.get("Mobile"),
							userMap.get("Mobile"),
							ConfigEnum.SourceNumber.getName(),
							Content,
							"-1" 
							});
			}
		}
		if(userName.toString().length()>1){
			return userName.toString();
		}else{
			return "";
		}
	}
	/**
	 * 获取保养提示短信内容
	 * @author jiyongtian IEMS3.6 2014-05-30 新增
	 **/
	private String getContensOfMaintAlertMails(String vclNo, String armValue,
			int mtnType) {
		StringBuffer strBuf = new StringBuffer();
		strBuf.append(vclNo+"需要进行"+armValue);
		switch(mtnType){
		case 1:
			strBuf.append("小时");
			break;
		case 2:
			strBuf.append("公里");
			break;
		case 3:
			strBuf.append("天");
			break;
		default:break;
		}
		strBuf.append("保养，请尽快保养。");
		return strBuf.toString();
	}

	/**
	 * 进出围栏提示获取短信接收人 20141016jinjiayu
	 * @return
	 */
	public List<Map<String, Object>> getSMSUsers_IOFenTip() {
		List<Map<String, Object>> list = null;
		StringBuffer sb = new StringBuffer("with tb4 as(SELECT smsas_id,ui.userid,ui.username,ui.mobile,ui.email,uo.OrganizationID,db.OrganizationCode");
		sb.append(" FROM sms_alarm_setinfo AS smsas INNER JOIN userinfo AS ui ON smsas.smsas_usp_id = ui.userid");
		sb.append(" left join userinfo_organization as uo on uo.UserID=ui.UserID");
		sb.append(" left join organization_db as db on CHARINDEX(cast(db.OrganizationID as varchar),cast(uo.organizationid as varchar)) >0");
		sb.append(" where UsefulLife>=GETDATE() and isnull(ui.mobile,'')<>'' and isnull(db.OrganizationCode,'')<>'' and SMSAS_SMSFenTip=1) ");
		sb.append(" select distinct smsas_id,userid,username,mobile,email,");
		sb.append(" OrganizationCode=STUFF((select ','+OrganizationCode from tb4 t5 where tb4.OrganizationID=t5.OrganizationID  for xml path('')),1,1,'') from tb4 ");
		
		list = this.baseDAO.execQuery(sb.toString(), new Object[] {});
				
		return list;
	}

	/**
	 * 进出围栏提示、时效预警发送短信 20141016jinjiayu
	 * @param sqlList  
	 * @param paramList
	 * @param user
	 * @param smsSendTimeList
	 * @param SMSContent
	 */
	public void IOSMSInfo(List<String> sqlList, List<Object[]> paramList,Map<String, Object> user, List<String> smsSendTimeList, String SMSContent, String type) {
		String smsSendTime = this.getTimingSendTimeFlt(smsSendTimeList);
		String strSqlSMSRec = "insert into SMS_SendRecord(SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,SSR_CreateType,SSR_MsgCID,SSR_MsgID)"
				+ "values(?,?,?,?,"+(smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+",?,'1',IDENT_CURRENT('Msg_Prompt'),IDENT_CURRENT('Msg_Prompt'));";

		// 发送短信信息
		//String strSqlSMSSend = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
		//		+ "values(?,?,?,?,"+smsSendTime+");";

		sqlList.add(strSqlSMSRec);
		//sqlList.add(strSqlSMSSend);

		paramList.add(new Object[] {
				MapGetter.getString(user, "userid"),
				MapGetter.getString(user, "username"),
				MapGetter.getString(user, "mobile"),
				SMSContent,
				type
				 });
		paramList.add(new Object[] {
				MapGetter.getString(user, "mobile"),
				ConfigEnum.SourceNumber.getName(),
				SMSContent, "-1"});
		
	}
	
	/**
	 * 进出围栏提示、时效预警发送短信 20141016jinjiayu
	 * @param sqlList  
	 * @param paramList
	 * @param user
	 * @param smsSendTimeList
	 * @param SMSContent
	 * @param state 
	 * @param sentype 
	 * @param vclid 
	 * @param gpstime 
	 * @param state 
	 * @param sentype 
	 */
	public void IOSMSInfo2(List<String> sqlList, List<Object[]> paramList,Map<String, Object> user, List<String> smsSendTimeList, String SMSContent,
			String type, String gpstime, String vclid, String sentype, String state) {
		String smsSendTime = this.getTimingSendTimeFlt(smsSendTimeList);
		String strSqlSMSRec = "insert into SMS_SendRecord(SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,SSR_CreateType,"+
				"SSR_MsgCID,SSR_MsgID)"
				+ "values(?,?,?,?,"+(smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+",?,'1'," ;
		if("3".equals(state)){
			strSqlSMSRec += "(select max(msgp_id) msgp_id from msg_prompt where msgp_type=16 and MsgP_VclID="+vclid+" and MsgP_MsgTime='"+gpstime+"' and MsgP_SecTypeId=2 and MsgP_State=3)," ;
			strSqlSMSRec += "(select max(msgp_id) msgp_id from msg_prompt where msgp_type=16 and MsgP_VclID="+vclid+" and MsgP_MsgTime='"+gpstime+"' and MsgP_SecTypeId=2 and MsgP_State=3));";
		}else{
			strSqlSMSRec += "IDENT_CURRENT('Msg_Prompt'),IDENT_CURRENT('Msg_Prompt'))";
		}

		// 发送短信信息
	//	String strSqlSMSSend = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
		//		+ "values(?,?,?,?,"+smsSendTime+");";

		sqlList.add(strSqlSMSRec);
	//	sqlList.add(strSqlSMSSend);

		paramList.add(new Object[] {
				MapGetter.getString(user, "userid"),
				MapGetter.getString(user, "username"),
				MapGetter.getString(user, "mobile"),
				SMSContent,
				type
				 });
		paramList.add(new Object[] {
				MapGetter.getString(user, "mobile"),
				ConfigEnum.SourceNumber.getName(),
				SMSContent, "-1"});
		
	}

	/**
	 * 时效预警获取短信接收人
	 * @return
	 */
	public List<Map<String, Object>> getSMSUsers_Eff() {
		List<Map<String, Object>> list = null;
		StringBuffer sb = new StringBuffer("SELECT smsas_id,ui.userid,ui.username,ui.mobile,ui.email");
		sb.append(" FROM sms_alarm_setinfo AS smsas");
		sb.append(" INNER JOIN userinfo AS ui ON smsas.smsas_usp_id = ui.userid");
		sb.append(" where UsefulLife>=GETDATE() and isnull(ui.mobile,'')<>'' and SMSAS_SMSEffAlarm=1");
		
		list = this.baseDAO.execQuery(sb.toString(), new Object[] {});
				
		return list;
	}
	/**发送短信，并保存入消息中心系统表中,调用的作业由：服务期报警、
	 * @author jiyongtian 20150215 iems3.7优化新增
	 * 
	 **/
	public void sendNoteInfo(List<String> sqlList, List<Object[]> paramList,
			Map<String, Object> map, List<Map<String, Object>> userList,String madeType) {
		if(null != map && null != userList && userList.size()>0){
			String sql = "";
			Object[] param = null;
			for(Map<String,Object> user:userList){
				sql = "insert into #tablename# (@_VclID,@_SType,@_State,@_MsgContent,@_Position,@_UserID,@_UserName,@_UserDBCode,@_UserDBName,@_Mobile,@_SendTime)" +
						"values(?,1,?,?,null,?,?,?,?,?,"+(MapGetter.getString(map, "SendTime").equalsIgnoreCase("null")?"GETDATE()":MapGetter.getString(map, "SendTime"))+");";
				param = new Object[]{
						MapGetter.getString(map, "VehicleID"),
						MapGetter.getString(map, "noteState"),
						MapGetter.getString(map, "SMSContent"),
//						MapGetter.getString(map, "Position"),
						MapGetter.getString(user, "UserID"),
						MapGetter.getString(user, "UserName"),
						MapGetter.getString(user, "UserDBCode"),
						MapGetter.getString(user, "UserDBName"),
						MapGetter.getString(user, "Mobile")
						
				};
				if(sql.length()>0){
					sql = sql.replaceAll("#tablename#",this.getNoteTableShort(madeType)).replaceAll("@", this.getNoteTableName(madeType));
					sqlList.add(sql);
				}
				if(null!=param){
					paramList.add(param);
				}
				//短信队列
			//	String sendSMS = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime) values(?,?,?,?,"+(MapGetter.getString(map, "SendTime"))+");";
			//	sqlList.add(sendSMS);
				paramList.add(new Object[] {
					MapGetter.getString(user, "Mobile"),
					ConfigEnum.SourceNumber.getName(),
					MapGetter.getString(map, "SMSContent"), 
					"-1"
					});
			}
		}
	}

	private String getNoteTableShort(String madeType) {
		String reStr = "";
		if(StringUtil.isValid(madeType)){
			if(madeType.equalsIgnoreCase("smsas_smsservice")){//服务期报警 SMSAS_SMSService
				reStr = "Note_ServerDeadLine";
			}
		}
		return reStr;
	}

	private String getNoteTableName(String madeType) {
		String reStr = "";
		if(StringUtil.isValid(madeType)){
			if(madeType.equalsIgnoreCase("smsas_smsservice")){//服务期报警 SMSAS_SMSService
				reStr = "NSD";
			}
		}
		return reStr;
	}
	/**
	 * 故障12小时报警发送短信
	 **/
	public boolean promptSMSInfoFltTwelve(List<String> sqlList,
			List<Object[]> paramList, Map<String, Object> SMSMap,
			Map<String, Object> user, List<String> smsSendTimeList) {

		//类型（1：短信白名单；2：短信过滤；3：实时发送短信）
		String SMSFC_Type = MapGetter.getString(user, "SMSFC_Type");
		//实时发送短信故障码—红色故障（1：选中）
		String SMSAS_SMSFltIsRed = MapGetter.getString(user, "SMSAS_SMSFltIsRed");
		//故障代码颜色
		String SysISM_CodeColorInfo = MapGetter.getString(SMSMap, "SysISM_CodeColorInfo");
		//短信--红色故障
		String SMSAS_SMSFltRed = MapGetter.getString(user, "SMSAS_SMSFltRed");
		//短信--黄色故障
		String SMSAS_SMSFltYellow = MapGetter.getString(user, "SMSAS_SMSFltYellow");
		//短信--其他故障
		String SMSAS_SMSFltOther = MapGetter.getString(user, "SMSAS_SMSFltOther");
		//故障分类
		String SMSAS_FltType = MapGetter.getString(user, "SMSAS_FltType");
		//短信--实时发送短信故障码—四级故障（1：选中）
		String SMSAS_SMSFltIsFour = MapGetter.getString(user, "SMSAS_SMSFltIsFour");
		//故障等级
		String fltLv = MapGetter.getString(SMSMap, "fltLv");
		//一级故障
		String SMSAS_SMSFltOne = MapGetter.getString(user, "SMSAS_SMSFltOne");
		//二级故障
		String SMSAS_SMSFltTwo = MapGetter.getString(user, "SMSAS_SMSFltTwo");
		//三级故障
		String SMSAS_SMSFltThree = MapGetter.getString(user, "SMSAS_SMSFltThree");
		//四级故障
		String SMSAS_SMSFltFour = MapGetter.getString(user, "SMSAS_SMSFltFour");
		
		String smsSendTime = "";
		if(SMSFC_Type.equals("3") || ((SMSAS_FltType.equals("2") && SMSAS_SMSFltIsRed.equals("true") && SysISM_CodeColorInfo.equals(ConfigEnum.FltCodeRed.getName())) || (SMSAS_FltType.equals("1") && SMSAS_SMSFltIsFour.equals("true") && fltLv.equals("4")))){	//实时发送
//			smsSendTime = "GETDATE()";
			smsSendTime = "null";
		}else if(SMSFC_Type.equals("1") || ( SMSAS_FltType.equals("2") && (SMSAS_SMSFltRed.equals(SysISM_CodeColorInfo) || SMSAS_SMSFltYellow.equals(SysISM_CodeColorInfo) 
				|| (SMSAS_SMSFltOther.equals("其他") && !SysISM_CodeColorInfo.equals("黄色")&& !SysISM_CodeColorInfo.equals("红色"))))
				|| ( SMSAS_FltType.equals("1") && ((SMSAS_SMSFltOne.equals("true")&&fltLv.equals("1")) || (SMSAS_SMSFltTwo.equals("true")&&fltLv.equals("2")) || (SMSAS_SMSFltThree.equals("true")&&fltLv.equals("3")) || (SMSAS_SMSFltFour.equals("true")&&fltLv.equals("4"))))){
			smsSendTime = this.getTimingSendTimeFlt(smsSendTimeList);
		}
		
		if (StringUtil.isNullOrEmpty(smsSendTime)) {
			// 业务记录短信信息
			String strSqlSMSRec = "insert into Note_Flt_Twelve(NFT_VclID,NFT_SType,NFT_State,NFT_MsgContent,NFT_Position,NFT_UserID,NFT_UserName,NFT_UserDBCode,NFT_UserDBName,NFT_Mobile,NFT_SendTime)" +
					"values(?,1,?,?,?,?,?,?,?,?,"+(smsSendTime.toLowerCase().equals("null")?"GETDATE()":smsSendTime)+");";

			// 发送短信信息
			String strSqlSMSSend = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
					+ "values(?,?,?,?,"+smsSendTime+");";

			sqlList.add(strSqlSMSRec);
			sqlList.add(strSqlSMSSend);

			paramList.add(new Object[] {
					MapGetter.getString(SMSMap, "MsgP_VclID"),
					"1",//故障、机械报警、传感器报警 时报警状态1-报警中，0-已解除
					MapGetter.getString(SMSMap, "SMSContent"),
					MapGetter.getString(SMSMap, "Position"),
					MapGetter.getString(user, "UserID"),
					MapGetter.getString(user, "UserName"),
					MapGetter.getString(user, "UserDBCode").substring(0,MapGetter.getString(user, "UserDBCode").length()-1),
					MapGetter.getString(user, "UserDBName").substring(0,MapGetter.getString(user, "UserDBName").length()-1),
					MapGetter.getString(user, "Mobile")
			});
			paramList.add(new Object[] {
					MapGetter.getString(user, "Mobile"),
					ConfigEnum.SourceNumber.getName(),
					MapGetter.getString(SMSMap, "SMSContent"), "-1"});
			return true;
		}else{
			return false;
		}
	}
}
